package com.jlastu.znb.entity;

import org.json.JSONException;
import org.json.JSONObject;

public class ChatMessage {
    private String message;
    private int avatarResId;

    public ChatMessage(String message, int avatarResId) {
        this.message = message;
        this.avatarResId = avatarResId;
    }

    public String getMessage() {
        return message;
    }

    public int getAvatarResId() {
        return avatarResId;
    }

    public JSONObject toJSON() {
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("message", message);
            jsonObject.put("avatarResId", avatarResId);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return jsonObject;
    }

    public static ChatMessage fromJSON(JSONObject jsonObject) {
        try {
            String message = jsonObject.getString("message");
            int avatarResId = jsonObject.getInt("avatarResId");
            return new ChatMessage(message, avatarResId);
        } catch (JSONException e) {
            e.printStackTrace();
            return null;
        }
    }
}